package com.bw.day03.address

import androidx.lifecycle.viewModelScope
import com.bw.base.net.entity.AddAddressEntity
import com.bw.base.net.entity.AddressEntity
import com.bw.base.net.entity.Res
import com.bw.base.net.mvvm.BaseViewModel
import com.bw.base.net.param.ParamAddAddress
import com.bw.day03.utlis.SingleLiveData
import kotlinx.coroutines.launch

class AddressViewModel : BaseViewModel(){
    val addressSuccess= SingleLiveData<Res<AddAddressEntity>>()
     val addressFail=SingleLiveData<String>()
    fun addAddress(paramAddAddress: ParamAddAddress){
        viewModelScope.launch {
            try {
                addressSuccess.postValue(apiService.addAddress(paramAddAddress))
            }catch (e: Exception){
                addressFail.postValue( e.message.toString())
            }
        }
    }

    val dressSuccess= SingleLiveData<Res<AddressEntity>>()
    val dressFail=SingleLiveData<String>()
    fun address(limit: Int,page: Int){
        viewModelScope.launch {
            try {
                dressSuccess.postValue(apiService.address(limit,page))
            }catch (e: Exception){
                dressFail.postValue(e.message.toString())
            }
        }
    }
}